package com.gxa.insurance.service.impl;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.exception.ExceptionCode;
import com.gxa.insurance.mapper.EtcApplyMapper;
import com.gxa.insurance.pojo.EtcApply;
import com.gxa.insurance.pojo.ThirdAdmin;
import com.gxa.insurance.service.EtcApplySevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author 10076
 */
@Service
public class EtcApplyServiceImpl  implements EtcApplySevice {
    @Autowired
    EtcApplyMapper etcApplyMapper;

    @Transactional()
    @Override
    public Integer insert(EtcApply etcApply) throws Exception {
        if(etcApply==null){
            throw new BusinessException(ExceptionCode.USER_NOT_FONUD);
        }
        return etcApplyMapper.insert(etcApply);
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public void delete(Integer id) throws Exception {
        if (id==null){
            throw new BusinessException(ExceptionCode.USER_NOT_FONUD);
        }
            etcApplyMapper.delete(id);
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public void update(EtcApply etcApply) throws Exception {
        if(etcApply==null){
            throw new BusinessException(ExceptionCode.USER_NOT_FONUD);
        }
           etcApplyMapper.update(etcApply);
    }

    @Override
    public List<Map<String, Object>> selectByPage(Integer page, Integer size) throws Exception {
        if(page<=0||size<=0){
            throw new BusinessException(ExceptionCode.WRONG_VALUE);
        }
        page =(page-1)*size;
       return etcApplyMapper.selectByPage(page, size);
    }

    @Override
    public List<EtcApply> selectAll() throws Exception {
      return  etcApplyMapper.selectAll();
    }

    @Override
    public List<EtcApply> selectLikeName(String name) throws Exception {
        List<EtcApply> etcApplies = etcApplyMapper.selectLikeName(name);
        if(etcApplies.size()==0){
            throw new BusinessException(ExceptionCode.CUSTOMER_IS_EMPTY);
        }
        return etcApplies;
    }
}
